package com.sunjy.demo1.controller;

import com.sunjy.common.annotation.BeanValid;
import com.sunjy.common.base.BaseController;
import com.sunjy.demo1.form.UserForm;
import com.sunjy.demo1.model.TestName;
import com.sunjy.demo1.service.TestServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import com.sunjy.common.domain.ApiResponseT;

import javax.validation.Valid;


@RestController
@RequestMapping("valid")
public class TestVlidController extends BaseController {
	
	@Autowired
	private TestServices testServices;
	

	@BeanValid
	@GetMapping(value = "/test1",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ApiResponseT test1(){
		return testServices.test1();
	}

	@GetMapping(value={""}, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ApiResponseT<TestName> getUserList() {
		TestName t1=new TestName();
		t1.setName("111");
		return ApiResponseT.success(t1);
	}

	@BeanValid()
	@PostMapping(value="test2", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String postUser(@RequestBody @Valid UserForm user, BindingResult bind) {
		return "success";
	}

	@BeanValid
	@GetMapping(value="/{id}",  produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ApiResponseT getUser(@PathVariable Long id) {
		return testServices.test1();
	}


	@BeanValid
	@PostMapping(value="/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String putUser(@Valid @RequestBody UserForm user, @PathVariable Long id , BindingResult bind) {
		return "success";
	}
	

}
